﻿///////////////////////////////////////////////////////////////
// This is generated code. 
//////////////////////////////////////////////////////////////
// Code is generated using LLBLGen Pro version: 2.6
// Code is generated on: 2012年10月23日 21:56:49
// Code is generated using templates: SD.TemplateBindings.SharedTemplates.NET20
// Templates vendor: Solutions Design.
// Templates version: 
//////////////////////////////////////////////////////////////
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections;
#if !CF
using System.Runtime.Serialization;
#endif
using System.Data;
using System.Xml.Serialization;
using SaleDiscount.Data;
using SaleDiscount.Data.FactoryClasses;
using SaleDiscount.Data.DaoClasses;
using SaleDiscount.Data.RelationClasses;
using SaleDiscount.Data.HelperClasses;
using SaleDiscount.Data.CollectionClasses;

using SD.LLBLGen.Pro.ORMSupportClasses;

namespace SaleDiscount.Data.EntityClasses
{
	
	// __LLBLGENPRO_USER_CODE_REGION_START AdditionalNamespaces
	// __LLBLGENPRO_USER_CODE_REGION_END

	/// <summary>
	/// Entity class which represents the entity 'Sale'. <br/><br/>
	/// 
	/// </summary>
	[Serializable]
	public partial class SaleEntity : CommonEntityBase, ISerializable
		// __LLBLGENPRO_USER_CODE_REGION_START AdditionalInterfaces
		// __LLBLGENPRO_USER_CODE_REGION_END	
	{
		#region Class Member Declarations
		private SaleDiscount.Data.CollectionClasses.SaleListingsCollection	_saleListings;
		private bool	_alwaysFetchSaleListings, _alreadyFetchedSaleListings;

		private EbayUserTokenEntity _ebayUserToken;
		private bool	_alwaysFetchEbayUserToken, _alreadyFetchedEbayUserToken, _ebayUserTokenReturnsNewIfNotFound;

		
		// __LLBLGENPRO_USER_CODE_REGION_START PrivateMembers
		// __LLBLGENPRO_USER_CODE_REGION_END
		#endregion

		#region Statics
		private static Dictionary<string, string>	_customProperties;
		private static Dictionary<string, Dictionary<string, string>>	_fieldsCustomProperties;

		/// <summary>All names of fields mapped onto a relation. Usable for in-memory filtering</summary>
		public static partial class MemberNames
		{
			/// <summary>Member name EbayUserToken</summary>
			public static readonly string EbayUserToken = "EbayUserToken";
			/// <summary>Member name SaleListings</summary>
			public static readonly string SaleListings = "SaleListings";


		}
		#endregion
		
		/// <summary>Static CTor for setting up custom property hashtables. Is executed before the first instance of this entity class or derived classes is constructed. </summary>
		static SaleEntity()
		{
			SetupCustomPropertyHashtables();
		}

		/// <summary>CTor</summary>
		public SaleEntity()
		{
			InitClassEmpty(null);
		}


		/// <summary>CTor</summary>
		/// <param name="id">PK value for Sale which data should be fetched into this Sale object</param>
		public SaleEntity(System.Int32 id)
		{
			InitClassFetch(id, null, null);
		}

		/// <summary>CTor</summary>
		/// <param name="id">PK value for Sale which data should be fetched into this Sale object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		public SaleEntity(System.Int32 id, IPrefetchPath prefetchPathToUse)
		{
			InitClassFetch(id, null, prefetchPathToUse);
		}

		/// <summary>CTor</summary>
		/// <param name="id">PK value for Sale which data should be fetched into this Sale object</param>
		/// <param name="validator">The custom validator object for this SaleEntity</param>
		public SaleEntity(System.Int32 id, IValidator validator)
		{
			InitClassFetch(id, validator, null);
		}


		/// <summary>Private CTor for deserialization</summary>
		/// <param name="info"></param>
		/// <param name="context"></param>
		protected SaleEntity(SerializationInfo info, StreamingContext context) : base(info, context)
		{
			_saleListings = (SaleDiscount.Data.CollectionClasses.SaleListingsCollection)info.GetValue("_saleListings", typeof(SaleDiscount.Data.CollectionClasses.SaleListingsCollection));
			_alwaysFetchSaleListings = info.GetBoolean("_alwaysFetchSaleListings");
			_alreadyFetchedSaleListings = info.GetBoolean("_alreadyFetchedSaleListings");

			_ebayUserToken = (EbayUserTokenEntity)info.GetValue("_ebayUserToken", typeof(EbayUserTokenEntity));
			if(_ebayUserToken!=null)
			{
				_ebayUserToken.AfterSave+=new EventHandler(OnEntityAfterSave);
			}
			_ebayUserTokenReturnsNewIfNotFound = info.GetBoolean("_ebayUserTokenReturnsNewIfNotFound");
			_alwaysFetchEbayUserToken = info.GetBoolean("_alwaysFetchEbayUserToken");
			_alreadyFetchedEbayUserToken = info.GetBoolean("_alreadyFetchedEbayUserToken");

			base.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());
			
			// __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
			// __LLBLGENPRO_USER_CODE_REGION_END
		}

		
		/// <summary>Performs the desync setup when an FK field has been changed. The entity referenced based on the FK field will be dereferenced and sync info will be removed.</summary>
		/// <param name="fieldIndex">The fieldindex.</param>
		protected override void PerformDesyncSetupFKFieldChange(int fieldIndex)
		{
			switch((SaleFieldIndex)fieldIndex)
			{
				case SaleFieldIndex.EBayUserTokenId:
					DesetupSyncEbayUserToken(true, false);
					_alreadyFetchedEbayUserToken = false;
					break;
				default:
					base.PerformDesyncSetupFKFieldChange(fieldIndex);
					break;
			}
		}
		
		/// <summary>Gets the inheritance info provider instance of the project this entity instance is located in. </summary>
		/// <returns>ready to use inheritance info provider instance.</returns>
		protected override IInheritanceInfoProvider GetInheritanceInfoProvider()
		{
			return InheritanceInfoProviderSingleton.GetInstance();
		}
		
		/// <summary> Will perform post-ReadXml actions</summary>
		protected override void PostReadXmlFixups()
		{
			_alreadyFetchedSaleListings = (_saleListings.Count > 0);

			_alreadyFetchedEbayUserToken = (_ebayUserToken != null);

		}
				
		/// <summary>Gets the relation objects which represent the relation the fieldName specified is mapped on. </summary>
		/// <param name="fieldName">Name of the field mapped onto the relation of which the relation objects have to be obtained.</param>
		/// <returns>RelationCollection with relation object(s) which represent the relation the field is maped on</returns>
		public override RelationCollection GetRelationsForFieldOfType(string fieldName)
		{
			return SaleEntity.GetRelationsForField(fieldName);
		}

		/// <summary>Gets the relation objects which represent the relation the fieldName specified is mapped on. </summary>
		/// <param name="fieldName">Name of the field mapped onto the relation of which the relation objects have to be obtained.</param>
		/// <returns>RelationCollection with relation object(s) which represent the relation the field is maped on</returns>
		public static RelationCollection GetRelationsForField(string fieldName)
		{
			RelationCollection toReturn = new RelationCollection();
			switch(fieldName)
			{
				case "EbayUserToken":
					toReturn.Add(SaleEntity.Relations.EbayUserTokenEntityUsingEBayUserTokenId);
					break;
				case "SaleListings":
					toReturn.Add(SaleEntity.Relations.SaleListingsEntityUsingSaleId);
					break;


				default:

					break;				
			}
			return toReturn;
		}



		/// <summary> ISerializable member. Does custom serialization so event handlers do not get serialized.
		/// Serializes members of this entity class and uses the base class' implementation to serialize the rest.</summary>
		/// <param name="info"></param>
		/// <param name="context"></param>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			info.AddValue("_saleListings", (!this.MarkedForDeletion?_saleListings:null));
			info.AddValue("_alwaysFetchSaleListings", _alwaysFetchSaleListings);
			info.AddValue("_alreadyFetchedSaleListings", _alreadyFetchedSaleListings);

			info.AddValue("_ebayUserToken", (!this.MarkedForDeletion?_ebayUserToken:null));
			info.AddValue("_ebayUserTokenReturnsNewIfNotFound", _ebayUserTokenReturnsNewIfNotFound);
			info.AddValue("_alwaysFetchEbayUserToken", _alwaysFetchEbayUserToken);
			info.AddValue("_alreadyFetchedEbayUserToken", _alreadyFetchedEbayUserToken);

			
			// __LLBLGENPRO_USER_CODE_REGION_START GetObjectInfo
			// __LLBLGENPRO_USER_CODE_REGION_END
			base.GetObjectData(info, context);
		}
		
		/// <summary> Sets the related entity property to the entity specified. If the property is a collection, it will add the entity specified to that collection.</summary>
		/// <param name="propertyName">Name of the property.</param>
		/// <param name="entity">Entity to set as an related entity</param>
		/// <remarks>Used by prefetch path logic.</remarks>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override void SetRelatedEntityProperty(string propertyName, IEntity entity)
		{
			switch(propertyName)
			{
				case "EbayUserToken":
					_alreadyFetchedEbayUserToken = true;
					this.EbayUserToken = (EbayUserTokenEntity)entity;
					break;
				case "SaleListings":
					_alreadyFetchedSaleListings = true;
					if(entity!=null)
					{
						this.SaleListings.Add((SaleListingsEntity)entity);
					}
					break;


				default:

					break;
			}
		}

		/// <summary> Sets the internal parameter related to the fieldname passed to the instance relatedEntity. </summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		/// <param name="fieldName">Name of field mapped onto the relation which resolves in the instance relatedEntity</param>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override void SetRelatedEntity(IEntity relatedEntity, string fieldName)
		{
			switch(fieldName)
			{
				case "EbayUserToken":
					SetupSyncEbayUserToken(relatedEntity);
					break;
				case "SaleListings":
					_saleListings.Add((SaleListingsEntity)relatedEntity);
					break;

				default:

					break;
			}
		}
		
		/// <summary> Unsets the internal parameter related to the fieldname passed to the instance relatedEntity. Reverses the actions taken by SetRelatedEntity() </summary>
		/// <param name="relatedEntity">Instance to unset as the related entity of type entityType</param>
		/// <param name="fieldName">Name of field mapped onto the relation which resolves in the instance relatedEntity</param>
		/// <param name="signalRelatedEntityManyToOne">if set to true it will notify the manytoone side, if applicable.</param>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override void UnsetRelatedEntity(IEntity relatedEntity, string fieldName, bool signalRelatedEntityManyToOne)
		{
			switch(fieldName)
			{
				case "EbayUserToken":
					DesetupSyncEbayUserToken(false, true);
					break;
				case "SaleListings":
					base.PerformRelatedEntityRemoval(_saleListings, relatedEntity, signalRelatedEntityManyToOne);
					break;

				default:

					break;
			}
		}

		/// <summary> Gets a collection of related entities referenced by this entity which depend on this entity (this entity is the PK side of their FK fields). These
		/// entities will have to be persisted after this entity during a recursive save.</summary>
		/// <returns>Collection with 0 or more IEntity objects, referenced by this entity</returns>
		public override List<IEntity> GetDependingRelatedEntities()
		{
			List<IEntity> toReturn = new List<IEntity>();


			return toReturn;
		}
		
		/// <summary> Gets a collection of related entities referenced by this entity which this entity depends on (this entity is the FK side of their PK fields). These
		/// entities will have to be persisted before this entity during a recursive save.</summary>
		/// <returns>Collection with 0 or more IEntity objects, referenced by this entity</returns>
		public override List<IEntity> GetDependentRelatedEntities()
		{
			List<IEntity> toReturn = new List<IEntity>();
			if(_ebayUserToken!=null)
			{
				toReturn.Add(_ebayUserToken);
			}


			return toReturn;
		}
		
		/// <summary> Gets a List of all entity collections stored as member variables in this entity. The contents of the ArrayList is
		/// used by the DataAccessAdapter to perform recursive saves. Only 1:n related collections are returned.</summary>
		/// <returns>Collection with 0 or more IEntityCollection objects, referenced by this entity</returns>
		public override List<IEntityCollection> GetMemberEntityCollections()
		{
			List<IEntityCollection> toReturn = new List<IEntityCollection>();
			toReturn.Add(_saleListings);

			return toReturn;
		}

		

		

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="id">PK value for Sale which data should be fetched into this Sale object</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 id)
		{
			return FetchUsingPK(id, null, null, null);
		}

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="id">PK value for Sale which data should be fetched into this Sale object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 id, IPrefetchPath prefetchPathToUse)
		{
			return FetchUsingPK(id, prefetchPathToUse, null, null);
		}

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="id">PK value for Sale which data should be fetched into this Sale object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <param name="contextToUse">The context to add the entity to if the fetch was succesful. </param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 id, IPrefetchPath prefetchPathToUse, Context contextToUse)
		{
			return Fetch(id, prefetchPathToUse, contextToUse, null);
		}

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="id">PK value for Sale which data should be fetched into this Sale object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <param name="contextToUse">The context to add the entity to if the fetch was succesful. </param>
		/// <param name="excludedIncludedFields">The list of IEntityField objects which have to be excluded or included for the fetch. 
		/// If null or empty, all fields are fetched (default). If an instance of ExcludeIncludeFieldsList is passed in and its ExcludeContainedFields property
		/// is set to false, the fields contained in excludedIncludedFields are kept in the query, the rest of the fields in the query are excluded.</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 id, IPrefetchPath prefetchPathToUse, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields)
		{
			return Fetch(id, prefetchPathToUse, contextToUse, excludedIncludedFields);
		}

		/// <summary> Refetches the Entity from the persistent storage. Refetch is used to re-load an Entity which is marked "Out-of-sync", due to a save action. 
		/// Refetching an empty Entity has no effect. </summary>
		/// <returns>true if Refetch succeeded, false otherwise</returns>
		public override bool Refetch()
		{
			return Fetch(this.Id, null, null, null);
		}

		/// <summary> Returns true if the original value for the field with the fieldIndex passed in, read from the persistent storage was NULL, false otherwise.
		/// Should not be used for testing if the current value is NULL, use <see cref="TestCurrentFieldValueForNull"/> for that.</summary>
		/// <param name="fieldIndex">Index of the field to test if that field was NULL in the persistent storage</param>
		/// <returns>true if the field with the passed in index was NULL in the persistent storage, false otherwise</returns>
		public bool TestOriginalFieldValueForNull(SaleFieldIndex fieldIndex)
		{
			return base.Fields[(int)fieldIndex].IsNull;
		}
		
		/// <summary>Returns true if the current value for the field with the fieldIndex passed in represents null/not defined, false otherwise.
		/// Should not be used for testing if the original value (read from the db) is NULL</summary>
		/// <param name="fieldIndex">Index of the field to test if its currentvalue is null/undefined</param>
		/// <returns>true if the field's value isn't defined yet, false otherwise</returns>
		public bool TestCurrentFieldValueForNull(SaleFieldIndex fieldIndex)
		{
			return base.CheckIfCurrentFieldValueIsNull((int)fieldIndex);
		}

				
		/// <summary>Gets a list of all the EntityRelation objects the type of this instance has.</summary>
		/// <returns>A list of all the EntityRelation objects the type of this instance has. Hierarchy relations are excluded.</returns>
		public override List<IEntityRelation> GetAllRelations()
		{
			return new SaleRelations().GetAllRelations();
		}


		/// <summary> Retrieves all related entities of type 'SaleListingsEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <returns>Filled collection with all related entities of type 'SaleListingsEntity'</returns>
		public SaleDiscount.Data.CollectionClasses.SaleListingsCollection GetMultiSaleListings(bool forceFetch)
		{
			return GetMultiSaleListings(forceFetch, _saleListings.EntityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'SaleListingsEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of type 'SaleListingsEntity'</returns>
		public SaleDiscount.Data.CollectionClasses.SaleListingsCollection GetMultiSaleListings(bool forceFetch, IPredicateExpression filter)
		{
			return GetMultiSaleListings(forceFetch, _saleListings.EntityFactoryToUse, filter);
		}

		/// <summary> Retrieves all related entities of type 'SaleListingsEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public SaleDiscount.Data.CollectionClasses.SaleListingsCollection GetMultiSaleListings(bool forceFetch, IEntityFactory entityFactoryToUse)
		{
			return GetMultiSaleListings(forceFetch, entityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'SaleListingsEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public virtual SaleDiscount.Data.CollectionClasses.SaleListingsCollection GetMultiSaleListings(bool forceFetch, IEntityFactory entityFactoryToUse, IPredicateExpression filter)
		{
 			if( ( !_alreadyFetchedSaleListings || forceFetch || _alwaysFetchSaleListings) && !base.IsSerializing && !base.IsDeserializing && !base.InDesignMode)
			{
				if(base.ParticipatesInTransaction)
				{
					if(!_saleListings.ParticipatesInTransaction)
					{
						base.Transaction.Add(_saleListings);
					}
				}
				_saleListings.SuppressClearInGetMulti=!forceFetch;
				if(entityFactoryToUse!=null)
				{
					_saleListings.EntityFactoryToUse = entityFactoryToUse;
				}
				_saleListings.GetMultiManyToOne(this, filter);
				_saleListings.SuppressClearInGetMulti=false;
				_alreadyFetchedSaleListings = true;
			}
			return _saleListings;
		}

		/// <summary> Sets the collection parameters for the collection for 'SaleListings'. These settings will be taken into account
		/// when the property SaleListings is requested or GetMultiSaleListings is called.</summary>
		/// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return. When set to 0, this parameter is ignored</param>
		/// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified (null), no sorting is applied.</param>
		public virtual void SetCollectionParametersSaleListings(long maxNumberOfItemsToReturn, ISortExpression sortClauses)
		{
			_saleListings.SortClauses=sortClauses;
			_saleListings.MaxNumberOfItemsToReturn=maxNumberOfItemsToReturn;
		}


		/// <summary> Retrieves the related entity of type 'EbayUserTokenEntity', using a relation of type 'n:1'</summary>
		/// <returns>A fetched entity of type 'EbayUserTokenEntity' which is related to this entity.</returns>
		public EbayUserTokenEntity GetSingleEbayUserToken()
		{
			return GetSingleEbayUserToken(false);
		}

		/// <summary> Retrieves the related entity of type 'EbayUserTokenEntity', using a relation of type 'n:1'</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
		/// <returns>A fetched entity of type 'EbayUserTokenEntity' which is related to this entity.</returns>
		public virtual EbayUserTokenEntity GetSingleEbayUserToken(bool forceFetch)
		{
			if( ( !_alreadyFetchedEbayUserToken || forceFetch || _alwaysFetchEbayUserToken) && !base.IsSerializing && !base.IsDeserializing  && !base.InDesignMode)			
			{
				bool performLazyLoading = base.CheckIfLazyLoadingShouldOccur(SaleEntity.Relations.EbayUserTokenEntityUsingEBayUserTokenId);

				EbayUserTokenEntity newEntity = new EbayUserTokenEntity();
				if(base.ParticipatesInTransaction)
				{
					base.Transaction.Add(newEntity);
				}
				bool fetchResult = false;
				if(performLazyLoading)
				{
					fetchResult = newEntity.FetchUsingPK(this.EBayUserTokenId);
				}
				if(fetchResult)
				{
					if(base.ActiveContext!=null)
					{
						newEntity = (EbayUserTokenEntity)base.ActiveContext.Get(newEntity);
					}
					this.EbayUserToken = newEntity;
				}
				else
				{
					if(_ebayUserTokenReturnsNewIfNotFound)
					{
						if(performLazyLoading || (!performLazyLoading && (_ebayUserToken == null)))
						{
							this.EbayUserToken = newEntity;
						}
					}
					else
					{
						this.EbayUserToken = null;
					}
				}
				_alreadyFetchedEbayUserToken = fetchResult;
				if(base.ParticipatesInTransaction && !fetchResult)
				{
					base.Transaction.Remove(newEntity);
				}
			}
			return _ebayUserToken;
		}


		/// <summary> Performs the insert action of a new Entity to the persistent storage.</summary>
		/// <returns>true if succeeded, false otherwise</returns>
		protected override bool InsertEntity()
		{
			SaleDAO dao = (SaleDAO)CreateDAOInstance();
			return dao.AddNew(base.Fields, base.Transaction);
		}
		
		/// <summary> Adds the internals to the active context. </summary>
		protected override void AddInternalsToContext()
		{
			_saleListings.ActiveContext = base.ActiveContext;

			if(_ebayUserToken!=null)
			{
				_ebayUserToken.ActiveContext = base.ActiveContext;
			}


		}


		/// <summary> Performs the update action of an existing Entity to the persistent storage.</summary>
		/// <returns>true if succeeded, false otherwise</returns>
		protected override bool UpdateEntity()
		{
			SaleDAO dao = (SaleDAO)CreateDAOInstance();
			return dao.UpdateExisting(base.Fields, base.Transaction);
		}
		
		/// <summary> Performs the update action of an existing Entity to the persistent storage.</summary>
		/// <param name="updateRestriction">Predicate expression, meant for concurrency checks in an Update query</param>
		/// <returns>true if succeeded, false otherwise</returns>
		protected override bool UpdateEntity(IPredicate updateRestriction)
		{
			SaleDAO dao = (SaleDAO)CreateDAOInstance();
			return dao.UpdateExisting(base.Fields, base.Transaction, updateRestriction);
		}
	
		/// <summary> Initializes the class with empty data, as if it is a new Entity.</summary>
		/// <param name="validatorToUse">Validator to use.</param>
		protected virtual void InitClassEmpty(IValidator validatorToUse)
		{
			OnInitializing();
			base.Fields = CreateFields();
			base.IsNew=true;
			base.Validator = validatorToUse;

			InitClassMembers();
			
			// __LLBLGENPRO_USER_CODE_REGION_START InitClassEmpty
			// __LLBLGENPRO_USER_CODE_REGION_END

			OnInitialized();
		}
		
		/// <summary>Creates entity fields object for this entity. Used in constructor to setup this entity in a polymorphic scenario.</summary>
		protected virtual IEntityFields CreateFields()
		{
			return EntityFieldsFactory.CreateEntityFieldsObject(SaleDiscount.Data.EntityType.SaleEntity);
		}
		
		/// <summary>Creates a new transaction object</summary>
		/// <param name="levelOfIsolation">The level of isolation.</param>
		/// <param name="name">The name.</param>
		protected override ITransaction CreateTransaction( IsolationLevel levelOfIsolation, string name )
		{
			return new Transaction(levelOfIsolation, name);
		}

		/// <summary>
		/// Creates the ITypeDefaultValue instance used to provide default values for value types which aren't of type nullable(of T)
		/// </summary>
		/// <returns></returns>
		protected override ITypeDefaultValue CreateTypeDefaultValueProvider()
		{
			return new TypeDefaultValue();
		}

		/// <summary>
		/// Gets all related data objects, stored by name. The name is the field name mapped onto the relation for that particular data element. 
		/// </summary>
		/// <returns>Dictionary with per name the related referenced data element, which can be an entity collection or an entity or null</returns>
		public override Dictionary<string, object> GetRelatedData()
		{
			Dictionary<string, object> toReturn = new Dictionary<string, object>();
			toReturn.Add("EbayUserToken", _ebayUserToken);
			toReturn.Add("SaleListings", _saleListings);


			return toReturn;
		}
		

		/// <summary> Initializes the the entity and fetches the data related to the entity in this entity.</summary>
		/// <param name="id">PK value for Sale which data should be fetched into this Sale object</param>
		/// <param name="validator">The validator object for this SaleEntity</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		protected virtual void InitClassFetch(System.Int32 id, IValidator validator, IPrefetchPath prefetchPathToUse)
		{
			OnInitializing();
			base.Validator = validator;
			InitClassMembers();
			base.Fields = CreateFields();
			bool wasSuccesful = Fetch(id, prefetchPathToUse, null, null);
			base.IsNew = !wasSuccesful;

			
			// __LLBLGENPRO_USER_CODE_REGION_START InitClassFetch
			// __LLBLGENPRO_USER_CODE_REGION_END

			OnInitialized();
		}

		/// <summary> Initializes the class members</summary>
		private void InitClassMembers()
		{
			_saleListings = new SaleDiscount.Data.CollectionClasses.SaleListingsCollection(new SaleListingsEntityFactory());
			_saleListings.SetContainingEntityInfo(this, "Sale");
			_alwaysFetchSaleListings = false;
			_alreadyFetchedSaleListings = false;

			_ebayUserToken = null;
			_ebayUserTokenReturnsNewIfNotFound = true;
			_alwaysFetchEbayUserToken = false;
			_alreadyFetchedEbayUserToken = false;


			PerformDependencyInjection();
			
			// __LLBLGENPRO_USER_CODE_REGION_START InitClassMembers
			// __LLBLGENPRO_USER_CODE_REGION_END
			OnInitClassMembersComplete();
		}

		#region Custom Property Hashtable Setup
		/// <summary> Initializes the hashtables for the entity type and entity field custom properties. </summary>
		private static void SetupCustomPropertyHashtables()
		{
			_customProperties = new Dictionary<string, string>();
			_fieldsCustomProperties = new Dictionary<string, Dictionary<string, string>>();

			Dictionary<string, string> fieldHashtable = null;
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("Id", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("EBayUserTokenId", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("SaleName", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("StartDate", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("EndDate", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("IsAuctionExcluded", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("DiscountRatio", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("DiscountType", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("IsFreeShipping", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("AllAuctionItems", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("AllFixedPriceItems", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("AllStoreInventoryItems", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("CategoryId", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("CreatedDate", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("UpdatedDate", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("StoreCatetoryId", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("PromotionSaleId", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("Status", fieldHashtable);
		}
		#endregion


		/// <summary> Removes the sync logic for member _ebayUserToken</summary>
		/// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
		/// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
		private void DesetupSyncEbayUserToken(bool signalRelatedEntity, bool resetFKFields)
		{
			base.PerformDesetupSyncRelatedEntity( _ebayUserToken, new PropertyChangedEventHandler( OnEbayUserTokenPropertyChanged ), "EbayUserToken", SaleEntity.Relations.EbayUserTokenEntityUsingEBayUserTokenId, true, signalRelatedEntity, "Sale", resetFKFields, new int[] { (int)SaleFieldIndex.EBayUserTokenId } );		
			_ebayUserToken = null;
		}
		
		/// <summary> setups the sync logic for member _ebayUserToken</summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		private void SetupSyncEbayUserToken(IEntity relatedEntity)
		{
			if(_ebayUserToken!=relatedEntity)
			{		
				DesetupSyncEbayUserToken(true, true);
				_ebayUserToken = (EbayUserTokenEntity)relatedEntity;
				base.PerformSetupSyncRelatedEntity( _ebayUserToken, new PropertyChangedEventHandler( OnEbayUserTokenPropertyChanged ), "EbayUserToken", SaleEntity.Relations.EbayUserTokenEntityUsingEBayUserTokenId, true, ref _alreadyFetchedEbayUserToken, new string[] {  } );
			}
		}

		/// <summary>Handles property change events of properties in a related entity.</summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnEbayUserTokenPropertyChanged( object sender, PropertyChangedEventArgs e )
		{
			switch( e.PropertyName )
			{
				default:
					break;
			}
		}


		/// <summary> Fetches the entity from the persistent storage. Fetch simply reads the entity into an EntityFields object. </summary>
		/// <param name="id">PK value for Sale which data should be fetched into this Sale object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <param name="contextToUse">The context to add the entity to if the fetch was succesful. </param>
		/// <param name="excludedIncludedFields">The list of IEntityField objects which have to be excluded or included for the fetch. 
		/// If null or empty, all fields are fetched (default). If an instance of ExcludeIncludeFieldsList is passed in and its ExcludeContainedFields property
		/// is set to false, the fields contained in excludedIncludedFields are kept in the query, the rest of the fields in the query are excluded.</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		private bool Fetch(System.Int32 id, IPrefetchPath prefetchPathToUse, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields)
		{
			try
			{
				OnFetch();
				IDao dao = this.CreateDAOInstance();
				base.Fields[(int)SaleFieldIndex.Id].ForcedCurrentValueWrite(id);
				dao.FetchExisting(this, base.Transaction, prefetchPathToUse, contextToUse, excludedIncludedFields);
				return (base.Fields.State == EntityState.Fetched);
			}
			finally
			{
				OnFetchComplete();
			}
		}


		/// <summary> Creates the DAO instance for this type</summary>
		/// <returns></returns>
		protected override IDao CreateDAOInstance()
		{
			return DAOFactory.CreateSaleDAO();
		}
		
		/// <summary> Creates the entity factory for this type.</summary>
		/// <returns></returns>
		protected override IEntityFactory CreateEntityFactory()
		{
			return new SaleEntityFactory();
		}

		#region Class Property Declarations
		/// <summary> The relations object holding all relations of this entity with other entity classes.</summary>
		public  static SaleRelations Relations
		{
			get	{ return new SaleRelations(); }
		}
		
		/// <summary> The custom properties for this entity type.</summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		public  static Dictionary<string, string> CustomProperties
		{
			get { return _customProperties;}
		}


		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'SaleListings' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathSaleListings
		{
			get
			{
				return new PrefetchPathElement(new SaleDiscount.Data.CollectionClasses.SaleListingsCollection(),
					(IEntityRelation)GetRelationsForField("SaleListings")[0], (int)SaleDiscount.Data.EntityType.SaleEntity, (int)SaleDiscount.Data.EntityType.SaleListingsEntity, 0, null, null, null, "SaleListings", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToMany);
			}
		}


		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'EbayUserToken' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathEbayUserToken
		{
			get
			{
				return new PrefetchPathElement(new SaleDiscount.Data.CollectionClasses.EbayUserTokenCollection(),
					(IEntityRelation)GetRelationsForField("EbayUserToken")[0], (int)SaleDiscount.Data.EntityType.SaleEntity, (int)SaleDiscount.Data.EntityType.EbayUserTokenEntity, 0, null, null, null, "EbayUserToken", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToOne);
			}
		}


		/// <summary>Returns the full name for this entity, which is important for the DAO to find back persistence info for this entity.</summary>
		[Browsable(false), XmlIgnore]
		public override string LLBLGenProEntityName
		{
			get { return "SaleEntity";}
		}

		/// <summary> The custom properties for the type of this entity instance.</summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		[Browsable(false), XmlIgnore]
		public override Dictionary<string, string> CustomPropertiesOfType
		{
			get { return SaleEntity.CustomProperties;}
		}

		/// <summary> The custom properties for the fields of this entity type. The returned Hashtable contains per fieldname a hashtable of name-value pairs. </summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		public  static Dictionary<string, Dictionary<string, string>> FieldsCustomProperties
		{
			get { return _fieldsCustomProperties;}
		}

		/// <summary> The custom properties for the fields of the type of this entity instance. The returned Hashtable contains per fieldname a hashtable of name-value pairs. </summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		[Browsable(false), XmlIgnore]
		public override Dictionary<string, Dictionary<string, string>> FieldsCustomPropertiesOfType
		{
			get { return SaleEntity.FieldsCustomProperties;}
		}

		/// <summary> The Id property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."Id"<br/>
		/// Table field type characteristics (type, precision, scale, length): Int, 10, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, true, true</remarks>
		public virtual System.Int32 Id
		{
			get { return (System.Int32)GetValue((int)SaleFieldIndex.Id, true); }
			set	{ SetValue((int)SaleFieldIndex.Id, value, true); }
		}
		/// <summary> The EBayUserTokenId property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."eBayUserTokenId"<br/>
		/// Table field type characteristics (type, precision, scale, length): Int, 10, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Int32 EBayUserTokenId
		{
			get { return (System.Int32)GetValue((int)SaleFieldIndex.EBayUserTokenId, true); }
			set	{ SetValue((int)SaleFieldIndex.EBayUserTokenId, value, true); }
		}
		/// <summary> The SaleName property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."SaleName"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 50<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.String SaleName
		{
			get { return (System.String)GetValue((int)SaleFieldIndex.SaleName, true); }
			set	{ SetValue((int)SaleFieldIndex.SaleName, value, true); }
		}
		/// <summary> The StartDate property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."StartDate"<br/>
		/// Table field type characteristics (type, precision, scale, length): DateTime, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.DateTime StartDate
		{
			get { return (System.DateTime)GetValue((int)SaleFieldIndex.StartDate, true); }
			set	{ SetValue((int)SaleFieldIndex.StartDate, value, true); }
		}
		/// <summary> The EndDate property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."EndDate"<br/>
		/// Table field type characteristics (type, precision, scale, length): DateTime, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.DateTime EndDate
		{
			get { return (System.DateTime)GetValue((int)SaleFieldIndex.EndDate, true); }
			set	{ SetValue((int)SaleFieldIndex.EndDate, value, true); }
		}
		/// <summary> The IsAuctionExcluded property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."IsAuctionExcluded"<br/>
		/// Table field type characteristics (type, precision, scale, length): Bit, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Boolean IsAuctionExcluded
		{
			get { return (System.Boolean)GetValue((int)SaleFieldIndex.IsAuctionExcluded, true); }
			set	{ SetValue((int)SaleFieldIndex.IsAuctionExcluded, value, true); }
		}
		/// <summary> The DiscountRatio property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."DiscountRatio"<br/>
		/// Table field type characteristics (type, precision, scale, length): Decimal, 18, 2, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Decimal DiscountRatio
		{
			get { return (System.Decimal)GetValue((int)SaleFieldIndex.DiscountRatio, true); }
			set	{ SetValue((int)SaleFieldIndex.DiscountRatio, value, true); }
		}
		/// <summary> The DiscountType property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."DiscountType"<br/>
		/// Table field type characteristics (type, precision, scale, length): SmallInt, 5, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Int16 DiscountType
		{
			get { return (System.Int16)GetValue((int)SaleFieldIndex.DiscountType, true); }
			set	{ SetValue((int)SaleFieldIndex.DiscountType, value, true); }
		}
		/// <summary> The IsFreeShipping property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."IsFreeShipping"<br/>
		/// Table field type characteristics (type, precision, scale, length): Bit, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Boolean IsFreeShipping
		{
			get { return (System.Boolean)GetValue((int)SaleFieldIndex.IsFreeShipping, true); }
			set	{ SetValue((int)SaleFieldIndex.IsFreeShipping, value, true); }
		}
		/// <summary> The AllAuctionItems property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."AllAuctionItems"<br/>
		/// Table field type characteristics (type, precision, scale, length): Bit, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Boolean AllAuctionItems
		{
			get { return (System.Boolean)GetValue((int)SaleFieldIndex.AllAuctionItems, true); }
			set	{ SetValue((int)SaleFieldIndex.AllAuctionItems, value, true); }
		}
		/// <summary> The AllFixedPriceItems property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."AllFixedPriceItems"<br/>
		/// Table field type characteristics (type, precision, scale, length): Bit, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Boolean AllFixedPriceItems
		{
			get { return (System.Boolean)GetValue((int)SaleFieldIndex.AllFixedPriceItems, true); }
			set	{ SetValue((int)SaleFieldIndex.AllFixedPriceItems, value, true); }
		}
		/// <summary> The AllStoreInventoryItems property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."AllStoreInventoryItems"<br/>
		/// Table field type characteristics (type, precision, scale, length): Bit, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Boolean AllStoreInventoryItems
		{
			get { return (System.Boolean)GetValue((int)SaleFieldIndex.AllStoreInventoryItems, true); }
			set	{ SetValue((int)SaleFieldIndex.AllStoreInventoryItems, value, true); }
		}
		/// <summary> The CategoryId property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."CategoryID"<br/>
		/// Table field type characteristics (type, precision, scale, length): BigInt, 19, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual Nullable<System.Int64> CategoryId
		{
			get { return (Nullable<System.Int64>)GetValue((int)SaleFieldIndex.CategoryId, false); }
			set	{ SetValue((int)SaleFieldIndex.CategoryId, value, true); }
		}
		/// <summary> The CreatedDate property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."CreatedDate"<br/>
		/// Table field type characteristics (type, precision, scale, length): DateTime, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.DateTime CreatedDate
		{
			get { return (System.DateTime)GetValue((int)SaleFieldIndex.CreatedDate, true); }
			set	{ SetValue((int)SaleFieldIndex.CreatedDate, value, true); }
		}
		/// <summary> The UpdatedDate property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."UpdatedDate"<br/>
		/// Table field type characteristics (type, precision, scale, length): DateTime, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.DateTime UpdatedDate
		{
			get { return (System.DateTime)GetValue((int)SaleFieldIndex.UpdatedDate, true); }
			set	{ SetValue((int)SaleFieldIndex.UpdatedDate, value, true); }
		}
		/// <summary> The StoreCatetoryId property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."StoreCatetoryID"<br/>
		/// Table field type characteristics (type, precision, scale, length): BigInt, 19, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual Nullable<System.Int64> StoreCatetoryId
		{
			get { return (Nullable<System.Int64>)GetValue((int)SaleFieldIndex.StoreCatetoryId, false); }
			set	{ SetValue((int)SaleFieldIndex.StoreCatetoryId, value, true); }
		}
		/// <summary> The PromotionSaleId property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."PromotionSaleID"<br/>
		/// Table field type characteristics (type, precision, scale, length): BigInt, 19, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual Nullable<System.Int64> PromotionSaleId
		{
			get { return (Nullable<System.Int64>)GetValue((int)SaleFieldIndex.PromotionSaleId, false); }
			set	{ SetValue((int)SaleFieldIndex.PromotionSaleId, value, true); }
		}
		/// <summary> The Status property of the Entity Sale<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "Sale"."Status"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 50<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual System.String Status
		{
			get { return (System.String)GetValue((int)SaleFieldIndex.Status, true); }
			set	{ SetValue((int)SaleFieldIndex.Status, value, true); }
		}

		/// <summary> Retrieves all related entities of type 'SaleListingsEntity' using a relation of type '1:n'.</summary>
		/// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiSaleListings()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
		public virtual SaleDiscount.Data.CollectionClasses.SaleListingsCollection SaleListings
		{
			get	{ return GetMultiSaleListings(false); }
		}

		/// <summary> Gets / sets the lazy loading flag for SaleListings. When set to true, SaleListings is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time SaleListings is accessed. You can always execute
		/// a forced fetch by calling GetMultiSaleListings(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchSaleListings
		{
			get	{ return _alwaysFetchSaleListings; }
			set	{ _alwaysFetchSaleListings = value; }	
		}		
				
		/// <summary>Gets / Sets the lazy loading flag if the property SaleListings already has been fetched. Setting this property to false when SaleListings has been fetched
		/// will clear the SaleListings collection well. Setting this property to true while SaleListings hasn't been fetched disables lazy loading for SaleListings</summary>
		[Browsable(false)]
		public bool AlreadyFetchedSaleListings
		{
			get { return _alreadyFetchedSaleListings;}
			set 
			{
				if(_alreadyFetchedSaleListings && !value && (_saleListings != null))
				{
					_saleListings.Clear();
				}
				_alreadyFetchedSaleListings = value;
			}
		}


		/// <summary> Gets / sets related entity of type 'EbayUserTokenEntity'. This property is not visible in databound grids.
		/// Setting this property to a new object will make the load-on-demand feature to stop fetching data from the database, until you set this
		/// property to null. Setting this property to an entity will make sure that FK-PK relations are synchronized when appropriate.</summary>
		/// <remarks>This property is added for conveniance, however it is recommeded to use the method 'GetSingleEbayUserToken()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the
		/// same scope. The property is marked non-browsable to make it hidden in bound controls, f.e. datagrids.</remarks>
		[Browsable(false)]
		public virtual EbayUserTokenEntity EbayUserToken
		{
			get	{ return GetSingleEbayUserToken(false); }
			set
			{
				if(base.IsDeserializing)
				{
					SetupSyncEbayUserToken(value);
				}
				else
				{
					if(value==null)
					{
						if(_ebayUserToken != null)
						{
							_ebayUserToken.UnsetRelatedEntity(this, "Sale");
						}
					}
					else
					{
						if(_ebayUserToken!=value)
						{
							((IEntity)value).SetRelatedEntity(this, "Sale");
						}
					}
				}
			}
		}

		/// <summary> Gets / sets the lazy loading flag for EbayUserToken. When set to true, EbayUserToken is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time EbayUserToken is accessed. You can always execute
		/// a forced fetch by calling GetSingleEbayUserToken(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchEbayUserToken
		{
			get	{ return _alwaysFetchEbayUserToken; }
			set	{ _alwaysFetchEbayUserToken = value; }	
		}
				
		/// <summary>Gets / Sets the lazy loading flag if the property EbayUserToken already has been fetched. Setting this property to false when EbayUserToken has been fetched
		/// will set EbayUserToken to null as well. Setting this property to true while EbayUserToken hasn't been fetched disables lazy loading for EbayUserToken</summary>
		[Browsable(false)]
		public bool AlreadyFetchedEbayUserToken
		{
			get { return _alreadyFetchedEbayUserToken;}
			set 
			{
				if(_alreadyFetchedEbayUserToken && !value)
				{
					this.EbayUserToken = null;
				}
				_alreadyFetchedEbayUserToken = value;
			}
		}

		/// <summary> Gets / sets the flag for what to do if the related entity available through the property EbayUserToken is not found
		/// in the database. When set to true, EbayUserToken will return a new entity instance if the related entity is not found, otherwise 
		/// null be returned if the related entity is not found. Default: true.</summary>
		[Browsable(false)]
		public bool EbayUserTokenReturnsNewIfNotFound
		{
			get	{ return _ebayUserTokenReturnsNewIfNotFound; }
			set { _ebayUserTokenReturnsNewIfNotFound = value; }	
		}



		/// <summary> Gets or sets a value indicating whether this entity is a subtype</summary>
		protected override bool LLBLGenProIsSubType
		{
			get { return false;}
		}

		/// <summary> Gets the type of the hierarchy this entity is in. </summary>
		[System.ComponentModel.Browsable(false), XmlIgnore]
		protected override InheritanceHierarchyType LLBLGenProIsInHierarchyOfType
		{
			get { return InheritanceHierarchyType.None;}
		}
		
		/// <summary>Returns the SaleDiscount.Data.EntityType enum value for this entity.</summary>
		[Browsable(false), XmlIgnore]
		public override int LLBLGenProEntityTypeValue 
		{ 
			get { return (int)SaleDiscount.Data.EntityType.SaleEntity; }
		}
		#endregion


		#region Custom Entity code
		
		// __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
		// __LLBLGENPRO_USER_CODE_REGION_END
		#endregion

		#region Included code

		#endregion
	}
}
